<template>
    <div class="photoinfo-container">
        <h3>{{photoinfo.title}}</h3>
        <p class="subtitle">
            <span>发表时间：{{photoinfo.add_time | dateFormat}}</span>
            <span>点击：{{photoinfo.click}}次</span>
        </p>
        <hr>
        <!-- 缩略图区域 -->
        <vue-preview :slides="list" class="imgPrev"></vue-preview>
        <!-- 内容区域 -->
        <div class="content" v-html="photoinfo.content"></div>
        <!-- 评论子组件区域 -->
        <comment-box :id="this.id"></comment-box>
    </div>
</template>

<script>
import comment from '../subcomponents/comment.vue'
import {Toast} from 'mint-ui'
import '../../css/imgPrev.scss'

export default {
    data() {
        return{
            id: this.$route.params.id,
            photoinfo: {}, //图片详情
            list: [] // 缩略图数组
        }
    },
    created() {
        this.getPhotoInfo();
        this.getThumbs();
    },
    methods: {
        getPhotoInfo() {
            this.$http.get("api/getimageInfo/" + this.id).then(result => {
                if(result.body.status === 0){
                    this.photoinfo = result.body.message[0];
                }
            })
        },
        getThumbs() {
            this.$http.get("api/getthumimages/" + this.id).then(result => {
                if(result.body.status === 0){
                    result.body.message.forEach(item => {
                        item.w = 600;
                        item.h = 400;
                        item.msrc = item.src;
                    });
                    this.list = result.body.message;
                }else{
                    Toast('获取图片信息失败！');
                }
            })
        }
    },
    components: {
        'comment-box': comment
    }
}
</script>

<style lang="scss" scoped>
.photoinfo-container{
    float: left;
    padding: 10px;
    h3{
        color: #26a2ff;
        font-size: 15px;
        text-align: center;
        margin: 15px 0;
    }
    .subtitle{
        display: flex;
        justify-content: space-between;
        font-size: 13px;
    }
    .content{
        font-size: 13px;
        line-height: 30px;
        float: left;
        text-indent: 2em;
    }
}
</style>